/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.pdx.cs.guavalib;

import edu.pdx.cs.guavadata.AppData;
import edu.pdx.cs.guavadata.Guava;
import edu.pdx.cs.guavadata.domain.Domain;
import edu.pdx.cs.guavadata.subclass.ControlType;
import edu.pdx.cs.guavadata.subclass.DataTable;
import edu.pdx.cs.guavadata.subclass.LaunchType;
import java.awt.Dimension;
import java.awt.Point;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JCheckBox;

/**
 *
 * @author VuTran
 */
public class GJCheckBox extends JCheckBox implements Guava {

    String gname;
    boolean isQmode;

    public GJCheckBox() {
        super();
        this.isQmode = false;
    }

    public LaunchType getLType() {
        return LaunchType.NA;
    }

    public ControlType getCType() {
        return ControlType.Attribute;
    }

    public String getGText() {
        return this.getText();
    }

    public String getGName() {
       if (gname == null)
           return this.getName();
       return gname;
    }

    public void setGName(String GName) {
        gname = GName;
    }

    public Point getGLocation() {
        return this.getLocation();
    }

    public Dimension getGSize() {
        return this.getSize();
    }

    public List<Guava> getGComponents() {
        return new ArrayList<Guava>();
    }

    public void gBind(String table, int i) {
        DataTable dt = AppData.ds.getTable(table);
        if (!dt.rows.isEmpty())
            dt.rows.get(i).put(this.getGName(), this.isSelected());
    }

    public void gBindFromDatabase(String table, int i) {
        DataTable dt = AppData.ds.getTable(table);
        if (!dt.rows.isEmpty()) {
            if (dt.rows.get(i).get(this.getGName()) != null)
                this.setSelected((Boolean) dt.rows.get(i).get(this.getGName()));
        }
    }

    public String getGDefault() {
        return String.valueOf(this.isSelected());
    }

    public String getGToolTip() {
        return this.getToolTipText();
    }

    public Domain getGDomain() {
        return new edu.pdx.cs.guavadata.domain.Boolean();
    }

    public Guava get(String s) {
        for (Guava g : this.getGComponents())
            if (g.getGName().equals(s))
                return g;
        return null;
    }

}
